﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using com.ClickCricket.bll;
using System.Drawing;

public partial class Blog : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LinkButton lnkBtn = new LinkButton();
        lnkBtn.Text = "Create new Blog";
        lnkBtn.PostBackUrl = "~/CreateBlog.aspx";
        Master.FindControl("ContentPlaceHolder1").Controls.Add(lnkBtn);
        Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<br/>"));
        Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<br/>"));

        List<com.ClickCricket.bll.Blog> _blogList = BlogService.Instance.getBlogs();
        if (_blogList.Count == 0)
        {
            Master.FindControl("ContentPlaceHolder1").Controls.Add(new LiteralControl("<H1>NO BLOGS AVAILABLE</H1>"));
        }
        else
        {
            Table t = new Table();
            t.GridLines = GridLines.Both;
            t.Width = 800;


            for (int i = 0; i < _blogList.Count; i++)
            {
                TableRow tr = new TableRow();
                Panel p = new Panel();
                p.BackColor = Color.White;
                com.ClickCricket.bll.Blog blg = (com.ClickCricket.bll.Blog)_blogList[i];
                Label lbl = new Label();
                lbl.Text = blg.Title.ToString();
                p.Controls.Add(lbl);
                p.Controls.Add(new LiteralControl("<br/>"));
                lbl = new Label();
                lbl.Text = blg.Date.ToString();
                p.Controls.Add(lbl);
                p.Controls.Add(new LiteralControl("<br/>"));
                p.Controls.Add(new LiteralControl("<br/>"));
                lbl = new Label();
                lbl.Text = blg.Data;
                p.Controls.Add(lbl);
                p.Controls.Add(new LiteralControl("<br/>"));
                p.Controls.Add(new LiteralControl("<br/>"));
                p.Controls.Add(new LiteralControl("<br/>"));
                TableCell tc = new TableCell();
                tc.Controls.Add(p);
                tr.Controls.Add(tc);
                t.Rows.Add(tr); ;

            }
            Master.FindControl("ContentPlaceHolder1").Controls.Add(t);
        }
    }
}
